package views;

import de.puc.defencetower.model.*;
import de.puc.defencetower.view.tui.console.*;
import play.api.templates.Html;
import views.html.mapelements.*;



import java.util.Timer;
import java.util.TimerTask;

/**
 * No HTML code here :-)
 * Using Play HTML Templates
 * The Html object is from the play framework and is for the html content.
 *
 * http://www.playframework.com/documentation/2.0/ScalaTemplates
 */
public class MapCreator  {


   public static String create(Map map) {


       String result = "";
       Html tabledata = Html.empty();
       MapCell[][] cells = map.getCells();
       // rows
       for (int i = 0; i < cells.length; i++) {
           Html row = Html.empty();

           // columns
           for (int j = 0; j < cells[i].length; j++) {
               Html column = Html.empty();
               String x = ""+j;
               String y = ""+i;

               MapCell mc = cells[i][j];

               Html cell = Html.empty();
               for (MapElement mapElement : mc.getMapElements()) {

                   if (mapElement instanceof Grass) {
                       cell.$plus(grass.render((Grass) mapElement));
                       //cell.$plus(tower.render((Tower) mapElement));
                   }
                   if (mapElement instanceof Street) {
                       cell.$plus(street.render((Street) mapElement));
                       //cell.$plus(monster.render((Monster) mapElement));
                   }

               }
               column.$plus(mapspan.render(cell, x, y));

               row.$plus(column);
           }

           tabledata.$plus(maprow.render(row));
       }
       result = maptable.render(tabledata).toString();
       return result;
   }
}
